<?php
include_once("./function.php");
//print_r($_GET);die;//Array ( [pid] => 75 )
extract($_GET);//$pid 
$pid=trim($pid);
//判断该商品是否有图片/图册
$sql="select thumb,pimgs from ts_product where pid='$pid'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
 $list=mysqli_fetch_assoc($res);
}
//print_r($list);die;//Array ( [thumb] => ./uploads/1901053706.jpg [pimgs] => ./uploads/1648353472.jpg,./uploads/1648358232.jpg,./uploads/1648355947.jpg )
//标题图的删除
if($list['thumb']!='')
{
	unlink($list['thumb']);
	//var_dump($one);
}

foreach($list as $v)
{
	$v;//./uploads/1901053706.jpg./uploads/1648353472.jpg,./uploads/1648358232.jpg,./uploads/1648355947.jpg
}

$more=explode(",",$v);
//print_r($more);//Array ( [0] => ./uploads/1648353472.jpg [1] => ./uploads/1648358232.jpg [2] => ./uploads/1648355947.jpg )
if($list['pimgs']!='')
{
	for($i=0;$i<count($more);$i++)
	{
		unlink($more[$i]);
		//var_dump($m);
	}
}

//删除商品
if(isset($pid))
{
	$sql="delete from ts_product where pid=$pid";
	$res=mysqli_query($link,$sql);
	if($res)
	{
		if(mysqli_affected_rows($link)==1)
		{
			msg("删除成功","product.php");exit;
		}
		else
		{
			msg("删除失败","product.php");exit;
		}
	}
}	
else
{
	echo "错误码:".mysqli_errno($link)."错误信息:".mysqli_error($link);exit;
}
	

?>